using System;
using System.Web;
using System.Web.Configuration;
using System.Configuration;

/// <summary>
/// Summary description for MyConfigurationManager
/// </summary>
/// 
namespace CE.Configuration
{
    public class MyConfigurationManager
    {
        public MyConfigurationManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static string GetConnectionString(string sName)
        {
            string _connectionName = ConfigurationManager.ConnectionStrings[sName].ToString();
            return _connectionName;
        }

        public static string GetAppSettingValue(string keyName)
        {
            string _appValue = ConfigurationManager.AppSettings[keyName].ToString();
            return _appValue;
        }

        public static void EncryptConfig(bool bEncrypt)
        {
            object path = "/CE_Dummy";
            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(path.ToString());
            ConfigurationSection appSettings = config.GetSection("connectionStrings");
            if (bEncrypt)
            {
                appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
            }
            else
            {
                appSettings.SectionInformation.UnprotectSection();
            }
            config.Save();
        }

        
    }
}